<?php
class BaseBrandAction extends HomeCommonAction{
    public function index(){
        $this->display('base_brand');
    }

    public function search(){
        $word = $_GET['word'];
        if(empty($word)){
            $word='a';
        }

        $BaseBrand = D('BaseBrand');
        $base_brand_list = $BaseBrand->where("py like '{$word}%'")->select();
        $this->assign('base_brand_list',$base_brand_list);
        $this->display('base_brand_list');
    }

    public function showInfo(){
        $id = $_GET['id'];
        $condition = array();
        $condition['id'] = $id;
        $BaseBrand = D('BaseBrand');
        $brand = $BaseBrand->where($condition)->find();

        $BaseCategory = D('BaseCategory');
        $condition = array();
        $condition['brand_id'] = $brand['id'];
        dump($condition);
        $category = $BaseCategory->relation('commodity')->where($condition)->order('id desc')->select();
		echo  $BaseCategory->getLastSql();
        if(!empty ($_GET['commodity'])){
            $commodity_word = $_GET['commodity'];
            $commodity_word =iconv('GB2312', 'UTF-8', $commodity_word);
            $BaseCommodity = D('BaseCommodity');
            $commodity = $BaseCommodity->where("name = '{$commodity_word}'")->find();
            $BrandModel = D('Brand');
            $brand_list = $BrandModel->where("commodity_id = '{$commodity['id']}'")->order('num desc')->select();
            $str = array();

            if(count($brand_list)>0){
                $max_num=  $BrandModel->where("commodity_id = '{$commodity['id']}'")->max('num');
                foreach($brand_list as $a)
                {
                    $str[] = $a['caption'];
                }
                for($i=0;$i<count($brand_list);$i++){
                    $brand_list[$i]['baifenbi'] = ($brand_list[$i]['num']/$max_num)*100;
                }
               
            }
            
            $this->assign('max_num', $max_num);
            $this->assign('brand_list', $brand_list);
           // print_r($str) ;die;
            $this->assign('brand_str',json_encode($str));
        }
      

        dump($category);
        $this->assign('brand', $brand);
        $this->assign('category', $category);
        $this->display('brand_list');


    }
}
?>
